#include "TcpServer.hpp"
#include "Common.hpp"
#include "Dict.hpp"

using namespace wxd;
void Usage(char* argv[])
{
    std::cerr<<"usage: ./"<<argv[0]<<" port"<<std::endl;
}


int main(int argc,char* argv[])
{   
    //./TcpServer port
    if(argc != 2)
    {
        Usage(argv);
        exit(USAGE_ERR);
    }

    uint16_t server_port = std::stoi(argv[1]);
    //创建Dict对象
    std::unique_ptr<Dict> ptr_dict = std::make_unique<Dict>();
    //创建TcpServer对象
    ptr_dict->Load();
    //方法一：传入lambda表达式
    auto task = [&ptr_dict](const std::string message){
        return ptr_dict->Translate(message);
    };
    std::unique_ptr<TcpServer> ptr_tcp_server = std::make_unique<TcpServer>(server_port,task);
    

    ptr_tcp_server->Init();
    ptr_tcp_server->Start();
    
    return 0;
}